package com.shtel.paas.monitorcenter.config.management.alarm.config.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;//@EnablePaasMybatis

import com.github.pagehelper.PageInfo;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmConfigDto;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmConfigParam;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmRulesDto;
import com.shtel.paas.monitorcenter.config.management.alarm.config.service.IWarningConfigService;
//import com.shtel.paas.sdk.core.RefreshableRestController;
//import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;
import com.shtel.paas.monitorcenter.config.management.alarm.config.service.WarningKpiService;

@MapperScan("com.shtel.paas.monitorcenter.config.management.alarm.config.mapper")
// mybatis存储库类的包路径
@RestController
public class warningConfigController {

	@Autowired
	IWarningConfigService service;

	@Autowired
	WarningKpiService warningKpiService;
	
	@RequestMapping("/getWarningConfig")
	public PageInfo<AlarmConfigDto> getWarningConfig(@RequestParam("monitoringIndex") String monitoringIndex,
			@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
		if (monitoringIndex.equals(""))
			monitoringIndex = null;
		return service.selectAll(monitoringIndex, page, pageSize);

	}

	@RequestMapping("/getWarningMonitoringKpi")
	public List<String> getWarningMonitoringKpi() {
		return service.selectMonitorIndex();
	}

	@RequestMapping("/updateWarningKpiConfig")
	public int updateWarningKpiConfig(@RequestParam("kpi_name") String kpi_name,
			@RequestParam("kpi_cmd") String kpi_cmd) {
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("kpi_name", kpi_name);
		paramMap.put("kpi_cmd", kpi_cmd);
//		warningKpiService.updateWarningKpiConfig(paramMap);
		return warningKpiService.updateWarningKpiConfig(paramMap);
	}
	
	
	@RequestMapping("/updateWarningConfig")
	public int updateWarningConfig(@RequestParam("desc") String desc,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh) {

		AlarmConfigParam alarmConfigParam = new AlarmConfigParam();
		
		alarmConfigParam.setDesc(desc);
		alarmConfigParam.setWarningLv1ValueHigh(warningLv1ValueHigh);
		alarmConfigParam.setWarningLv1ValueLow(warningLv1ValueLow);
		alarmConfigParam.setWarningLv2ValueHigh(warningLv2ValueHigh);
		alarmConfigParam.setWarningLv2ValueLow(warningLv2ValueLow);
		alarmConfigParam.setWarningLv3ValueHigh(warningLv3ValueHigh);
		alarmConfigParam.setWarningLv3ValueLow(warningLv3ValueLow);
		
		return service.updateConfig(alarmConfigParam);
	}

	@RequestMapping("/insertWarningConfig")
	public int insertWarningConfig(@RequestParam("desc") String desc, @RequestParam("kpi") String kpi,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh,
			@RequestParam("kpiType") String kpiType,
			@RequestParam("kpiCmd") String kpiCmd) {
		AlarmRulesDto param = new AlarmRulesDto();
		param.setDesc(desc);
		param.setWarningLv1ValueHigh(warningLv1ValueHigh);
		param.setWarningLv1ValueLow(warningLv1ValueLow);
		param.setWarningLv2ValueHigh(warningLv2ValueHigh);
		param.setWarningLv2ValueLow(warningLv2ValueLow);
		param.setWarningLv3ValueHigh(warningLv3ValueHigh);
		param.setWarningLv3ValueLow(warningLv3ValueLow);
		param.setKpi(kpi);
		param.setKpiType(kpiType);
		param.setKpiCmd(kpiCmd);
		return service.insertConfig(param);

	}

	@RequestMapping("/deleteWarningConfig")
	public int deleteWarningConfig(@RequestParam("desc") String desc) {
		return service.deleteConfig(desc);
	}
}
